package edu.bit.water.service;

import edu.bit.water.dao.TableCleanProductDao;
import edu.bit.water.entity.CleanProductSub1;
import edu.bit.water.entity.MetaCleanProductSub1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TableCleanProductService {
    @Autowired
    private TableCleanProductDao tableCleanProductDao;

    public List<MetaCleanProductSub1> getMetaData(String standardNumber, String page) {
        if(page.equals("sub1")) return tableCleanProductDao.getSub1MetaData(standardNumber);
        else if(page.equals("sub2")) return tableCleanProductDao.getSub2MetaData(standardNumber);
        else if(page.equals("sub3")) return tableCleanProductDao.getSub3MetaData(standardNumber);
        else if(page.equals("sub4")) return tableCleanProductDao.getSub4MetaData(standardNumber);
        else return tableCleanProductDao.getSub5MetaData(standardNumber);
    }

    public void insert(String indicator, int lastId, String page) {
        if(page.equals("sub1")) tableCleanProductDao.insertSub1(indicator, lastId);
        else if(page.equals("sub2")) tableCleanProductDao.insertSub2(indicator, lastId);
        else if(page.equals("sub3")) tableCleanProductDao.insertSub3(indicator, lastId);
        else if(page.equals("sub4")) tableCleanProductDao.insertSub4(indicator, lastId);
        else tableCleanProductDao.insertSub5(indicator, lastId);
    }

    public List<CleanProductSub1> select(int lastId, String page) {
        if(page.equals("sub1")) return tableCleanProductDao.sub1Select(lastId);
        else if(page.equals("sub2")) return tableCleanProductDao.sub2Select(lastId);
        else if(page.equals("sub3")) return tableCleanProductDao.sub3Select(lastId);
        else if(page.equals("sub4")) return tableCleanProductDao.sub4Select(lastId);
        else return tableCleanProductDao.sub5Select(lastId);
    }

    public void update(int id, String rank, String content, String page) {
        if(page.equals("sub1")) tableCleanProductDao.updateSub1(id, content, rank);
        else if(page.equals("sub2")) tableCleanProductDao.updateSub2(id, content, rank);
        else if(page.equals("sub3")) tableCleanProductDao.updateSub3(id, content, rank);
        else if(page.equals("sub4")) tableCleanProductDao.updateSub4(id, content, rank);
        else tableCleanProductDao.updateSub5(id, content, rank);
    }

    public void updateIncludeInput(int id, String rank, String content, double input1, double input2, String page) {
        if(page.equals("sub1")) tableCleanProductDao.updateSub1IncludeInput(id, content, rank, input1, input2);
        else if(page.equals("sub2")) tableCleanProductDao.updateSub2IncludeInput(id, content, rank, input1, input2);
        else if(page.equals("sub3")) tableCleanProductDao.updateSub3IncludeInput(id, content, rank, input1, input2);
        else if(page.equals("sub4")) tableCleanProductDao.updateSub4IncludeInput(id, content, rank, input1, input2);
        else tableCleanProductDao.updateSub5IncludeInput(id, content, rank, input1, input2);
    }

    public void stateUpdate(int id, String stdState) {
        tableCleanProductDao.stateUpdate(id, stdState);
    }


}
